var publicJs = require("../../public.js");

Page({
  data: {
    password: '',
    disabled: true
  },
  onLoad: function (options) {
    this.setData({
      mobile: options.mobile,
      code: options.code,
      sendcode: options.sendcode
    })
  }, 
  passwordChange: function (e) {
    //密码
    if (e.detail.value.length > 0) {
      this.setData({
        disabled: false
      });
    } else {
      this.setData({
        disabled: true
      });
    }
    this.data.password = e.detail.value
  },
  reg: function () {
    //注册
    publicJs.JsonPost("Personal/register", {
      user_name: this.data.mobile,
      mobile: this.data.mobile,
      ems_code: this.data.code,
      user_pwd: this.data.password,
      user_pwd2: this.data.password,
      send_ems_code: this.data.sendcode
    }, function (data) {
      publicJs.showLoading("注册中...请稍后...");
      console.log(data);

      if (data !== false) {
        //缓存用户信息
        wx.setStorageSync("userId", data.id);
        wx.setStorageSync("userName", data.user_name);
        wx.setStorageSync("realName", data.real_name);
        wx.setStorageSync("mobile", data.mobile);
        wx.setStorageSync("avatar", data.avatar);
        wx.setStorageSync("userData", JSON.stringify(data));

        publicJs.closeLoading();
        wx.switchTab({
          url: '../index/index'
        })
      }
    })

  }
})